import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:work/pages/route/app_route.dart';
import 'package:work/util/app_design.dart';
import 'package:work/util/route_aware_state.dart';

class MainApp extends StatelessWidget {
  const MainApp({Key? key}) : super(key: key);

  static const _locale = Locale('zh', "CN");

  @override
  Widget build(BuildContext context) {
    Get.config(
      enableLog: false,
      defaultPopGesture: true,
      defaultOpaqueRoute: false,
      defaultDurationTransition: const Duration(milliseconds: 250),
    );
    final body = GetMaterialApp(
      title: '画包包',
      defaultTransition: Transition.cupertino, // 页面默认切换动画
      themeMode: ThemeMode.light,
      locale: _locale,
      initialRoute: 'main',
      getPages: AppRoute.pages,
      unknownRoute: AppRoute.noExist,
      builder: (ctx, child) {
        AppDesign.init(ctx);
        child = _buildTextScale(ctx, child!);
        // child = AutoSizeUtil.appBuilder(ctx, child);
        return DefaultTextStyle(
          style: const TextStyle(
            fontFamily: 'PingFang SC',
          ),
          child: child,
        );
      },
    );
    return ProviderScope(
      child: body,
    );
  }

  /// 全局设置：文字大小不随系统设置改变
  Widget _buildTextScale(BuildContext context, Widget child) {
    return MediaQuery(
      data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
      child: child,
    );
  }
}
